/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.prashant.sqlduniya.dbexplorer;

import java.awt.Event;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.util.lookup.Lookups;
import org.prashant.sqlduniya.sqlmanager.TableBean;

/**
 *
 * @author prashant
 */
public class TableBeanNode extends AbstractNode {

    public TableBeanNode(TableBean bean) {
        super(Children.LEAF, Lookups.singleton(bean));
        this.setName(bean.getLabel());
        this.setDisplayName(bean.getLabel());
        this.setIconBaseWithExtension("org/prashant/sqlduniya/dbexplorer/table-icon16.png");;
        bean.addPropertyChangeListener(new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent arg) {
                if ("label".equals(arg.getPropertyName())) {
                    setDisplayName(arg.getNewValue() + "");
                }
            }
        });
    }

    @Override
    public Action[] getActions(boolean popup) {
        return new Action[]{new MyAction()};
    }

    private class MyAction extends AbstractAction {

        public MyAction() {
            putValue(NAME, "Do Something");
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            TableBean obj = getLookup().lookup(TableBean.class);
            JOptionPane.showMessageDialog(null, "Hello from " + obj.getLabel() + "," + obj.getCatalog());
        }
    }
}
